import Vue from 'vue'


import App from './App.vue'
import router from './router/router'
import './plugins/element.js'

import store from './store'

import './assets/css/global.css'

import vueMiniPlayer from 'vue-mini-player'
import 'vue-mini-player/lib/vue-mini-player.css'
Vue.use(vueMiniPlayer)

import Vant, {
  Lazyload
} from 'vant';
import 'vant/lib/index.css';
Vue.use(Lazyload, {
  lazyComponent: true
});
Vue.use(Vant);

import Textra from 'vue-textra'
Vue.use(Textra)
import VEmojiPicker from 'v-emoji-picker';
Vue.use(VEmojiPicker);

import axios from 'axios'

// axios.defaults.baseURL = 'http://127.0.0.1:3000/'


Vue.prototype.$http = axios
Vue.prototype.imgUrl = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/Shopimg/'
Vue.prototype.iconUrl = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/MobileShop/'
Vue.prototype.evImage = 'http://139.196.93.237:8050/static/img/'
Vue.prototype.BubbleUrl = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/Bubble/'
Vue.prototype.fileUrl = 'http://139.196.93.237:8050/static/fileword/'
Vue.prototype.videoUrl = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/Videonumber/'
Vue.prototype.Chatvoice = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/Chatvoice/'
Vue.prototype.goodsComment = 'https://sss-1306551685.cos.ap-guangzhou.myqcloud.com/goodsComment/'




import wsConnection from "./utils/webScoket";
Vue.prototype.socketApi = wsConnection

import VueCropper from 'vue-cropper'
Vue.use(VueCropper)

Vue.prototype.$axios = axios

Vue.config.productionTip = false

Vue.filter('dateFormat', function (timeVal) {
  const dt = new Date(timeVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, 0)
  const hh = (dt.getHours() + '').padStart(2, 0)
  const mm = (dt.getMinutes() + '').padStart(2, 0)
  const ss = (dt.getSeconds() + '').padStart(2, 0)
  return `${y}-${m}-${d} ${hh}:${mm}`

})
Vue.filter('dateDay', function (timeVal) {
  const dt = new Date(timeVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, 0)
  const hh = (dt.getHours() + '').padStart(2, 0)
  const mm = (dt.getMinutes() + '').padStart(2, 0)
  const ss = (dt.getSeconds() + '').padStart(2, 0)
  return `${y}-${m}-${d}`

})


import FileUpload from "./utils/Fileupload";
Vue.prototype.$util = FileUpload;

router.beforeEach((to, from, next) => {

  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    if (localStorage.getItem('TOKEN_EMAIL')) { //判断本地是否存在TOKEN_EMAIL
      next();
    } else {
      if (to.path === '/login') {
        next();
      } else {
        next({
          path: '/login'
        })
      }
    }
  } else {
    next();
  }
  /*如果本地 存在 token 则 不允许直接跳转到 登录页面*/
  if (to.fullPath == "/login") {
    if (localStorage.getItem('TOKEN_EMAIL')) {
      next({
        path: from.fullPath
      });
    } else {
      next();
    }
  }
});
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')